package com.jason.campusinn.utils;/*
package com.jason.campusinn.utils;

import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.util.EncodingUtils;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.view.View;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;

import com.jason.campusinn.constants.Constants;
import com.jason.campusinn.constants.InterfaceConstants;
import com.jason.campusinn.constants.SharedPreferenceConstants;
import com.jason.campusinn.view.XListView;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest;

public class CommonMethodUtils {
	private static long lastClickTime;
	public static boolean isFastDoubleClick() {
		long time = System.currentTimeMillis();
		if ( time - lastClickTime < 800) {
			return true;
		}
		lastClickTime = time;
		return false;
	}

	public static boolean isFastDoubleClick(long timelong) {
		long time = System.currentTimeMillis();
		if ( time - lastClickTime < timelong) {
			return true;
		}
		lastClickTime = time;
		return false;
	}

	*/
/**
	 * 使用反射根据属性名称获取属性值
	 *
	 * @param  methodName 获取属性方法
	 * @param  o 操作对象
	 * @return Object 属性值
	 *//*

	public static Object getFieldValueByName(String methodName, Object o)
	{
		try
		{
			Method method = o.getClass().getMethod(methodName, new Class[] {});
			Object value = method.invoke(o, new Object[] {});
			return value;
		} catch (Exception e)
		{
			System.out.println("属性不存在");
			return null;
		}
	}

	*/
/**
	 * 打开APK文件
	 *
	 * @param context
	 * @param file
	 * @return
	 *//*

	public static boolean OpenApkFile(Context context, File file) {
		if (!checkFileEndings(file, ".apk")) {
			return false;
		}
		Intent it = new Intent();
		it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		it.setAction(android.content.Intent.ACTION_VIEW);
		Uri u = Uri.fromFile(file);
		it.setDataAndType(u, "application/vnd.android.package-archive");
		context.startActivity(it);
		return true;
	}

	*/
/**
	 * 检查文件后缀
	 *
	 * @param file
	 * @param fileEndings
	 * @return
	 *//*

	private static boolean checkFileEndings(File file, String... fileEndings) {
		if (file == null || fileEndings == null || fileEndings.length == 0
				|| !file.exists()) {
			return false;
		}
		for (String s : fileEndings) {
			if (file.getPath().toLowerCase().endsWith(s)) {
				return true;
			}
		}
		return false;
	}

	*/
/**
	 * 检测邮箱地址是否合法
	 *
	 * @param email
	 * @return true合法 false不合法
	 *//*

	public static boolean isEmail(String email) {
		if (null == email || "".equals(email)) return false;
//        Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
//        Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配
		Pattern p = Pattern.compile(
				"^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\\\.][A-Za-z]{2,3}([\\\\.][A-Za-z]{2})?$");//复杂匹配
		Matcher m = p.matcher(email);
		return m.matches();
	}

	//检测手机号码是否合法
	public static String REGEX_PHONE_EMAIL = "^\\d{11}$|^(([0-9]|[A-Z]|[a-z]) " +
			"+ (_|\\.)?([0-9]|[A-Z]|[a-z])+@(\\w|\\.){1,}\\.([A-Z]|[a-z]){2,})$";

	*/
/**
	 * 检测手机号码是否合法
	 *
	 * @param Phone
	 * @return true合法 false不合法
	 *//*

	public static boolean isPhone(String Phone) {
		if (null == Phone || "".equals(Phone)) return false;
		Pattern p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$");//复杂匹配
		Matcher m = p.matcher(Phone);
		return m.matches();
	}

	*/
/**
	 * 检测手机号码是否合法
	 *
	 * @param Phone 13位
	 * @return true合法 false不合法
	 *//*

	public static boolean isPhone13(String Phone) {
		if (null == Phone || "".equals(Phone)) return false;
		Pattern p = Pattern.compile("^[1][3,4,5,8][0-9,\\n\\s*\\r ]{11}$");//复杂匹配
		Matcher m = p.matcher(Phone);
		return m.matches();
	}

//	*/
/**
//	 * 检测是否登录
//	 *//*

//	public static boolean checkInfo(Context context)
//	{
//		if(!SharedPreferenceUtil.getSharedBooleanData(context, SharedPreferenceConstants.LOGIN_STATUS, false))
//		{
//			Intent intent = new Intent();
////            intent.setClass(context, InitializeActivity.class);
//			intent.setClass(context, LoginActivity.class);
//			intent.putExtra("from_tag", 1);
//			context.startActivity(intent);
//			Activity activity = (Activity) context;
//			activity.overridePendingTransition(R.anim.dialog_enter, R.anim.translate_state);
//			return false;
//		}
//		return true;
//	}

	*/
/**
	 * 检测密码是否合法
	 * 中英文混合，至少 minsize位
	 *//*

	public static boolean checkPassword(Context context,String password, int minsize, int maxsize)
	{
		if(isEmpty(password))
		{
			Toast.makeText(context, "密码不能为空！", Toast.LENGTH_SHORT).show();
			return false;
		}
		String regEx = "^[a-zA-Z]{6,}$";
		Pattern pattern = Pattern.compile(regEx);
		Matcher mather = pattern.matcher(password);

		String regEx2 = "^[0-9]{6,}$";
		Pattern pattern2 = Pattern.compile(regEx2);
		Matcher mather2 = pattern2.matcher(password);

		String regEx3 = "^([0-9]|[A-Z]|[a-z]){6,}$";
		Pattern pattern3 = Pattern.compile(regEx3);
		Matcher mather3 = pattern3.matcher(password);

		if (!mather3.matches()) {
			Toast.makeText(context, "密码为字母或数字至少"+minsize+"位！", Toast.LENGTH_SHORT).show();
			return false;
		}

		if(password.length() > maxsize)
		{
			Toast.makeText(context, "密码长度不能超过"+maxsize+"位！", Toast.LENGTH_SHORT).show();
			return false;
		}
		return true;
	}


	*/
/**
	 * 读取Assets数据
	 *
	 * @param context
	 * @param fileName
	 * @return
	 *//*

	public static String getAssetsData(Context context, String fileName) {

		String json;

		try {

			// 得到资源中的asset数据流
			InputStream in = context.getResources().getAssets().open(fileName);
			int length = in.available();
			byte[] buffer = new byte[length];

			in.read(buffer);
			in.close();
			json = EncodingUtils.getString(buffer, "UTF-8");

		} catch (Exception e) {
			json = null;
		}
//        LogUtil.d("Assets JSON Data ====="+json);
		return json;
	}

	public static boolean isEmpty(String string) {
		return string == null || string.trim().length() == 0;
	}

	public static String phoneNumChange(String phoneNumber) {
		String number = phoneNumber.replaceAll("^(\\d{3})(\\d{4})(\\d{4})$", "$1****$3");
		return number;
	}

	*/
/**
	 * 计算美物单品价格
	 * materialPrice 面料价格
	 * materialQuantity 面料用量
	 * pricing_coefficient 定价系数
	 * processesCost 加工费
	 *//*

	public static int getGoodsPrice(String materialPrice, String materialQuantity, String pricing_coefficient,String processesCost) {
		LogUtil.d("价格：pricing_coefficient = " + pricing_coefficient);
		double formerPrice, mPrice = 0, mQuantity = 0, pricing_ceffic = 1,processes_cost = 0;
		int price = 0;
		if (!isEmpty(materialPrice)) {
			mPrice = Double.valueOf(materialPrice);
		}
		if (!isEmpty(materialQuantity)) {
			mQuantity = Double.valueOf(materialQuantity);
		}
		if (!isEmpty(pricing_coefficient)) {
			pricing_ceffic = Double.valueOf(pricing_coefficient);
		}

		if (!isEmpty(processesCost)) {
			processes_cost = Double.valueOf(processesCost);
		}

		formerPrice = (mPrice * mQuantity  + processes_cost)* pricing_ceffic;
		double first = Math.floor(formerPrice);
		double second = Math.floor(first / 10);
		double thrid = second * 10;
		double fourth;
		int tenNum = (int) (thrid % 10);
		if (tenNum == 0) {
			fourth = thrid - 10;
		} else {
			fourth = thrid;
		}
		double fifth = Math.floor(fourth / 100);
		double sixth = fifth * 100;
		price = (int) (sixth + 98);
		if (price <= 98){
			price = 98;
		}
		LogUtil.d("价格：price = " + price);
		return price;
	}

//	*/
/**
//	 * 隐性登录方法
//	 *
//	 * @param context
//	 * @param userName
//	 * @param password
//	 *//*

//	public static void login(final Context context, final String userName, final String password) {
//		JSONObject object = new JSONObject();
//		try {
//			object.put("phoneNo", userName);
//			object.put("password", password);
//		} catch (JSONException e) {
//			e.printStackTrace();
//		}
//		LogUtil.d("object:" + object.toString());
//		HttpUtil.sendJsonRequest(HttpRequest.HttpMethod.POST, InterfaceConstants.BASE_URL + "login", object.toString(), new HttpRequestCallBack<Object>() {
//			@Override
//			public void onSuccessed(ResponseInfo<Object> responseInfo) {
//				LogUtil.d("login success :" + responseInfo.result);
//				try {
//					JSONObject response_json = new JSONObject(responseInfo.result.toString());
//					if (response_json.getInt("returnCode") == 200) {
//						//保存登录状态
//						SharedPreferenceUtil.setSharedBooleanData(context, SharedPreferenceConstants.LOGIN_STATUS, true);
//						//保存用户名、密码
//						SharedPreferenceUtil.setSharedStringData(context, SharedPreferenceConstants.USER_NAME, userName);
//						SharedPreferenceUtil.setSharedStringData(context, SharedPreferenceConstants.USER_PASSWORD, password);
//
//						JSONObject return_data = response_json.getJSONObject("returnData");
//						String token = return_data.getString("X-AUTH-TOKEN");
//						if (token != null) {
//							LoginInfo.getInstance(context).setToken(token);
//						}
//						final LoginInfoBean login_info = new Gson().fromJson(responseInfo.result.toString(), LoginInfoBean.class);
//						if (login_info != null) {
//							LoginInfo.getInstance(context).saveLoginInfo(login_info);
//							Log.d("000", "RongIM token = " + login_info.getReturnData().getIIMTocken());
//							WannaApp.getInstance().connectIM(login_info.getReturnData().getIIMTocken(),0);
//						}
//					}
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
//			}
//
//			@Override
//			public void onFailed(HttpException exception, String reason) {
//				int retCode = exception.getExceptionCode();
//				LogUtil.d("接口 登录 onFailed()" + exception.getExceptionCode());
//			}
//		}, 0);
//	}

//	*/
/**判断是否登录*//*

//	public static boolean isLogined(Context mContext){
//		if (isEmpty(LoginInfo.getInstance(mContext).getToken())){
////            Toast.makeText(mContext,"请先登录",Toast.LENGTH_SHORT).show();
////            Intent intent = new Intent(mContext, InitializeActivity.class);
//			Intent intent = new Intent(mContext, LoginActivity.class);
//			intent.putExtra("from_tag", 1);
//			mContext.startActivity(intent);
//			Activity activity = (Activity) mContext;
//			activity.overridePendingTransition(R.anim.dialog_enter, R.anim.translate_state);
//		}
//		return !isEmpty(LoginInfo.getInstance(mContext).getToken());
//	}

	public static void getConflictData( final Context  context ){

		HttpUtil.sendJsonRequest(HttpRequest.HttpMethod.GET, InterfaceConstants.GET_TECHNICAL_CONFICT_DETAILS, "",
				new HttpRequestCallBack<Object>() {

					@Override
					public void onSuccessed(ResponseInfo<Object> responseInfo) {
						if (!CommonMethodUtils.isEmpty( responseInfo.result.toString())){
							SharedPreferenceUtil.setSharedStringData(context, SharedPreferenceConstants.CONFLICT_DETAIL,
									responseInfo.result.toString());
						}
					}

					@Override
					public void onFailed(HttpException exception, String reason) {

					}
				}, 0);

//        SharedPreferenceUtil.setSharedStringData( context, SharedPreferenceConstants.CONFLICT_DETAIL);
	}

	*/
/**获取造物数据 *//*

	public static void getCreateBaseData(final Context mContext,final boolean isFirst){
		final Intent intent = new Intent(Constants.ACTION_GETTED_CREATE_DATA);
		SharedPreferenceUtil.setSharedBooleanData(mContext,SharedPreferenceConstants.IS_LOADED_CREATE_DATA,false);
		HttpUtil.sendJsonRequest(HttpRequest.HttpMethod.GET, InterfaceConstants.GET_CREATE_DETAIL_DATA, "", new HttpRequestCallBack<Object>() {
			@Override
			public void onSuccessed(ResponseInfo<Object> responseInfo) {
//                GetCreateDataBase  getCreateDataBase = new Gson().fromJson((String) responseInfo.result, GetCreateDataBase.class);
				if (!CommonMethodUtils.isEmpty(responseInfo.result.toString())){
					SharedPreferenceUtil.setSharedStringData(mContext, SharedPreferenceConstants.CRATE_FACTORY_BASE_DATA, responseInfo.result.toString());
					SharedPreferenceUtil.setSharedBooleanData(mContext, SharedPreferenceConstants.IS_LOADED_CREATE_DATA, true);
					intent.putExtra("flag",1);
					mContext.sendBroadcast(intent);
				} else {
					if (isFirst){
						intent.putExtra("flag",2);
					} else {
						intent.putExtra("flag",3);
					}
					mContext.sendBroadcast(intent);
				}
			}

			@Override
			public void onFailed(HttpException exception, String reason) {
				SharedPreferenceUtil.setSharedBooleanData(mContext, SharedPreferenceConstants.IS_LOADED_CREATE_DATA, true);
				SharedPreferenceUtil.setSharedStringData(mContext, SharedPreferenceConstants.CRATE_FACTORY_BASE_DATA, "");
				if (isFirst){
					intent.putExtra("flag",2);
				} else {
					intent.putExtra("flag",3);
				}
				mContext.sendBroadcast(intent);
			}
		}, 0);
	}


	*/
/**
	 * 验证身份证号是否符合规则
	 * @param text 身份证号
	 * @return
	 *//*

	public static boolean isIdCard(String text) {
		String regx = "[0-9]{17}x";
		String reg1 = "[0-9]{15}";
		String regex = "[0-9]{18}";
		return text.matches(regx) || text.matches(reg1) || text.matches(regex);
	}


	*/
/**
	 * 校验银行卡卡号
	 * @param cardId
	 * @return
	 *//*

	public static boolean checkBankCard(String cardId) {
		char bit = getBankCardCheckCode(cardId.substring(0, cardId.length() - 1));
		return cardId.charAt(cardId.length() - 1) == bit;
	}

	*/
/**
	 * 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位
	 * @param nonCheckCodeCardId
	 * @return
	 *//*

	public static char getBankCardCheckCode(String nonCheckCodeCardId) {
//        if(nonCheckCodeCardId == null || nonCheckCodeCardId.trim().length() == 0
//                || !nonCheckCodeCardId.matches("//d+")) {
//            throw new IllegalArgumentException("Bank card code must be number!");
//        }
		char[] chs = nonCheckCodeCardId.trim().toCharArray();
		int luhmSum = 0;
		for(int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
			int k = chs[i] - '0';
			if(j % 2 == 0) {
				k *= 2;
				k = k / 10 + k % 10;
			}
			luhmSum += k;
		}
		return (luhmSum % 10 == 0) ? '0' : (char)((10 - luhmSum % 10) + '0');
	}

	*/
/**
	 * 格式化银行卡号，每4位加空格
	 * @param cardNumber
	 *//*

	public static String formatBankCardNumber(String cardNumber){
		StringBuilder stringBuilder = new StringBuilder();
		int integerCount = cardNumber.length()/4;
		int remainderCount = cardNumber.length()%4;
		String end = cardNumber.substring(cardNumber.length() - remainderCount, cardNumber.length());
		for (int i=0;i<integerCount;i++){
			stringBuilder.append(cardNumber.substring(i*4,i*4+4)+" ");
		}
		stringBuilder.append(end);
		LogUtil.d("银行卡格式化============" + stringBuilder.toString());
		return stringBuilder.toString();
	}

	*/
/**
	 * 格式化手机号，155 6666 8888
	 * @param phoneNum
	 * @return
	 *//*

	public static String formatPhoneNumber(String phoneNum){
		phoneNum = PhoneNumberFommatter.NumberFommatter(phoneNum);
		StringBuilder stringBuilder = new StringBuilder();
		String start = phoneNum.substring(0,3);
		String middle = phoneNum.substring(3, 7);
		String end = phoneNum.substring(7,11);
		stringBuilder.append(start).append(" ").append(middle).append(" ").append(end);
		LogUtil.d("手机号格式化============"+stringBuilder.toString());
		return stringBuilder.toString();
	}
	*/
/**将HashMap转换成Json*//*

	public static String hashMapToJson(HashMap<String, String> map) {
		String string = "{";
		for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
			Map.Entry e = (Map.Entry) it.next();
			string += "\"" + e.getKey() + "\":";
			string += "\"" + e.getValue() + "\",";
		}
		string = string.substring(0, string.lastIndexOf(","));
		string += "}";
		return string;
	}

	*/
/**
	 * 获取listview高度
	 * @return
	 *//*

	public static int getListViewScrollY(ListView listView) {
		View c = listView.getChildAt(0);
		if (c == null) {
			return 0;
		}
		int firstVisiblePosition = listView.getFirstVisiblePosition();
		int top = c.getTop();
		return -top + firstVisiblePosition * c.getHeight() ;
	}

	*/
/**
	 * 获取Xlistview高度
	 * @return
	 *//*

	public static int getListViewScrollY(XListView listView) {
		View c = listView.getChildAt(1);
		if (c == null) {
			return 0;
		}
		int firstVisiblePosition = listView.getFirstVisiblePosition();
		int top = c.getTop();
		return -top + firstVisiblePosition * c.getHeight() ;
	}
	*/
/**
	 * 获取Xlistview高度
	 * @return
	 *//*

	public static int getListViewScrollY(GridView gridView) {
		View c = gridView.getChildAt(0);
		if (c == null) {
			return 0;
		}
		int firstVisiblePosition = gridView.getFirstVisiblePosition();
		int top = c.getTop();
		return -top + firstVisiblePosition * c.getHeight() ;
	}

	*/
/**
	 * 检测网络是否可用
	 *
	 * @param context
	 * @return
	 *//*

	public static boolean isNetWorkConnected(Context context) {
		if (context != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
			if (mNetworkInfo != null) {
				return mNetworkInfo.isAvailable();
			}
		}

		return false;
	}

	*/
/**
	 * 检测Sdcard是否存在
	 *
	 * @return
	 *//*

	public static boolean isExitsSdcard() {
		if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
			return true;
		else
			return false;
	}

	static String getResString(Context context, int resId){
		return context.getResources().getString(resId);
	}


	public static String getTopActivity(Context context) {
		ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

		if (runningTaskInfos != null)
			return runningTaskInfos.get(0).topActivity.getClassName();
		else
			return "";
	}

}
*/
